﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dotnet.FormExtensions
{
    public static partial class Ext
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="isEnable"></param>
        public static void SetButtonEnableAsync(this Button btn,bool isEnable)
        {
            try
            {
                if (btn.InvokeRequired)
                {
                    var InvokeCallback = new Action<Button, bool>(SetButtonEnableAsync);
                    if (btn.IsDisposed == true)
                        return;
                    btn.Invoke(InvokeCallback, btn, isEnable);
                }
                else
                {
                    if (btn.IsDisposed)
                        return;
                    btn.Enabled = isEnable;
                }
            }
            catch(Exception ex)
            {

            }
        }
    }
}
